﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Management/manage.master" AutoEventWireup="true" CodeFile="PicList.aspx.cs" Inherits="Management_Products_PicList" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <script type="text/javascript" src="<%=ResolveUrl("~/Scripts/jquery-ui-dd-sortable.min.js") %>"></script>
    <script type="text/javascript">
        function resetsortable() {
            $("#pics").sortable({
                'update': function (event, ui) {
                    console.log(ui);
                },
                //鼠标接触即开始排序
                'tolerance': 'pointer',
                //定位动画
                'revert': true,
                'opacity': 0.7,
                'cursor': 'move'
            });
        }
        $(function () {
            //拖拽排序
            $("#pics").sortable({
                'update': function (event, ui) {
                    console.log(ui);
                },
                //鼠标接触即开始排序
                'tolerance': 'pointer',
                //定位动画
                'revert': true,
                'opacity': 0.7,
                'cursor': 'move'
            });
            

            $("#sort").click(function () {
                var pics = [];
                $(".picblock").each(function (k, v) {
                    pics.push({
                        PicID: $(this).data("id"),
                        PicName: $(this).data("name"),
                        Url: $(this).data("url"),
                        ProductID: $(this).data("productid"),
                        Sort: k
                    });
                });
                $.ajax({
                    type: "POST",
                    url: '<%=ResolveUrl("~/handlers/PicHandler.ashx") %>',
                    dataType: "json",
                    data: { picdata: JSON.stringify({ "PicList": pics }) },
                    success: function (data) {
                        if (data.Status == "0") {
                            alert("保存成功!");
                            window.location.href = 'List.aspx';
                        } else {
                            alert("保存时发生错误!请重试...");
                        }
                    },
                    error: function (err) {
                        alert("保存时发生错误!请重试...");
                        window.location.reload();
                    }
                });
            });

            $("#chkPickAll").change(function () {
                if ($(this).is(":checked")) {
                    $("#pics").find("input:checkbox").attr('checked', 'checked');
                } else {
                    $("#pics").find("input:checkbox").removeAttr('checked');
                }
            });
        });
    </script>
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnableScriptGlobalization="true" EnableScriptLocalization="true" AsyncPostBackTimeout="36000">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <h2 class="clearfix">
                <span class="float_l">照片列表</span>
                <asp:LinkButton ID="lbtnADD" runat="server" CssClass="btn" 
                    onclick="lbtnADD_Click" style="position:absolute;right:20px;">添加照片</asp:LinkButton>
            </h2>
            <div id="pics" class="block">
                <asp:Repeater ID="Repeater1" runat="server">
                    <ItemTemplate>
                        <div class="picblock" data-id='<%#Eval("PicID").ToString() %>' data-name='<%#Eval("PicName").ToString() %>' data-url='<%#Eval("Url").ToString() %>' data-productid='<%#Eval("ProductID").ToString() %>'>
                            <div>
                                <asp:HyperLink ID="hlnkUrl" runat="server" NavigateUrl='<%#ResolveUrl(Eval("Url").ToString()) %>' ToolTip='<%#Eval("Url").ToString() %>' BorderWidth="0" Target="_blank">
                                    <img src='<%#ResolveUrl(Eval("Url").ToString()) %>' alt='<%#Eval("PicName").ToString() %>' width="200" height="200" border="0" />
                                </asp:HyperLink>
                            </div>
                            <p class="dot"><asp:CheckBox ID="chkCheck" runat="server" /><asp:Label ID="lblName" runat="server"
                                    Text='<%#Eval("PicName").ToString() %>'></asp:Label></p>
                            <asp:HiddenField ID="hidPicID" Value='<%#Eval("PicID").ToString() %>' runat="server" />
                        </div>
                    </ItemTemplate>
                </asp:Repeater>
                <div class="pager margin10_tb">
                <asp:Repeater ID="rptPageFliper" runat="server">
                    <ItemTemplate>
                        <span class='<%#(((PageNumberItem)Container.DataItem).IsCurrentPage) ? "current": string.Empty%>' class="paging">
                            <asp:LinkButton ID="lbtnPager" runat="server" CommandName="<%# ((PageNumberItem)Container.DataItem).PageNumberCommand%>"
                                Text="<%# ((PageNumberItem)Container.DataItem).PageNumberText%>" Enabled='<%# !(((PageNumberItem)Container.DataItem).IsCurrentPage) %>'
                                Style='<%#(((PageNumberItem)Container.DataItem).IsCurrentPage) ? "color:#eee;": "color:#eee;"%>'
                                Font-Underline="false"></asp:LinkButton>
                        </span>
                    </ItemTemplate>
                </asp:Repeater>
                </div>
                <div class="margin10_tb">
                    <input id="chkPickAll" type="checkbox" />全选
                    <asp:LinkButton ID="lbtnDelete" runat="server" CssClass="btn" onclick="lbtnDelete_Click" OnClientClick="javascript:return confirm('确认删除么？');">删除选中的图片</asp:LinkButton>
                    <a id="sort" class="btn">保存当前排序</a>
                    <asp:LinkButton ID="lbtnCancel" runat="server" CssClass="btn" onclick="lbtnCancel_Click">返回</asp:LinkButton>
                </div>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>

